<template>
	<view class="home-page">
		<u-navbar leftIconColor="rgba(255,255,255,0.0)" :autoBack="false" :placeholder="true"
			bgColor="rgba(255,255,255,0.0)">
			<view slot="center" class="nav-title">
				抢购
			</view>
		</u-navbar>
		<view class="content">
			<view class="panic" v-if="info.start_time">
				<view class="panic-title">
					立拍优选<text>抢购倒计时</text>
				</view>
				<u-count-down :time="info.countdown * 1000" @finish="finsh" @change="onChange" format="HH:mm:ss" autoStart millisecond>
					<view class="time">
						<view class="time__custom">
							<text class="time__custom__item">{{ timeData.hours>10?timeData.hours:timeData.hours}}</text>
						</view>
						<text class="time__doc">时</text>
						<view class="time__custom">
							<text class="time__custom__item">{{ timeData.minutes }}</text>
						</view>
						<text class="time__doc">分</text>
						<view class="time__custom">
							<text class="time__custom__item">{{ timeData.seconds }}</text>
						</view>
						<text class="time__doc">秒</text>
					</view>
				</u-count-down>
			</view>
			<view class="box">
				<view class="item">
					<view class="time">
						{{info.start_time}}
					</view>
					<view class="clock">
						<view class="line"></view>
						<image src="../../static/home/clock.png" mode=""></image>
						<view class="line"></view>
					</view>
					<view class="time">
						预约时间
					</view>
				</view>
				<view class="item">
					<view class="time">
						{{info.end_time}}
					</view>
					<view class="time" style="margin-top: 20rpx;">
						进场时间
					</view>
				</view>
			</view>
			<view style="margin-top: 100rpx;">
				<!-- <view class="image">
					<image src="../../static/home/qiang.png" mode=""></image>
				</view> -->
				<view class="image-btn" v-if="info.countdown > 0">
					<image @click="goyuyue" v-if="info.has_appointment == 0" src="../../static/home/yuyue1.png" mode=""></image>
					<image  v-else src="../../static/home/yuyue2.png" mode=""></image>
				</view>
				<view class="image-btn" v-else>
					<image @click="gojinru"  src="../../static/home/yuyue3.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info: {},
				timeData: {},
			}
		},
		onLoad() {
			this.posttime()
		},
		methods: {
			finsh(){
				uni.showLoading({
					mask:true
				})
				this.posttime()
				setTimeout(()=>{
					uni.hideLoading()
				},1000)
			},
			gojinru(){
				if(this.info.has_appointment == 0){
					uni.showToast({
						title:'您未预约本场抢购！不能进入！',
						icon:'none'
					})
					return
				}
				uni.navigateTo({
					url:'/pages/buying/list/index'
				})
			},
			goyuyue(){
				uni.showLoading({
					mask:true
				})
				this.$Request({
					method: 'POST',
					url: '/api/Trade/makeAppointment',
					data: {},
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.posttime()
					}
				})
			},
			onChange(e) {
				this.timeData = e
			},
			posttime() {
				this.$Request({
					method: 'POST',
					url: '/api/Trade/catelist',
					data: {},
					ismsg: false,
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.home-page {
		background-image: url('../../static/home/home-bg2.png');
		background-repeat: no-repeat;
		background-size: 100% 340px;
		min-height: 80vh;
		position: relative;
		padding-top: 360rpx;
		.nav-title {
			color: #000000;
		}

		.content {
			width: 100%;
			padding: 30rpx;
			background-color: #fff;
			border-top-right-radius: 30rpx;
			border-top-left-radius: 30rpx;
			min-height: 50vh;

			.panic {
				background: linear-gradient(to left, #FDE9D9, #FDE0E8);
				border-radius: 20rpx;
				padding: 30rpx;


				.panic-title {
					text-align: center;
					font-size: 34rpx;
					font-weight: 500;
					color: #FD586C;

					text {
						margin-left: 10rpx;
						color: #000000;
					}
				}

				.time {
					@include flex;
					align-items: center;
					justify-content: center;
					margin-top: 20rpx;

					&__custom {
						border-radius: 4px;
						/* #ifndef APP-NVUE */
						display: flex;
						/* #endif */
						justify-content: center;
						align-items: center;

						&__item {
							padding: 10rpx 20rpx;
							border-radius: 20rpx;
							background-color: #FD586C;
							font-size: 32rpx;
							font-weight: bold;
							color: #fff;
							margin-left: 20rpx;
						}
					}

					&__doc {
						color: #000000;
						margin-left: 10rpx;
					}
				}
			}

			.image {
				text-align: center;
				padding-top: 80rpx;

				image {
					width: 300rpx;
					height: 300rpx;
				}
			}

			.image-btn {
				text-align: center;
				padding-top: 20rpx;
				.btn{
					width: 220rpx;
					border-radius: 30rpx;
					color: #fff;
					padding: 15rpx 20rpx;
					background-color: rgba(255, 0, 0, 1.0);
					margin: 0 auto;
				}
				image {
					width: 500rpx;
					height: 85rpx;
				}
			}

			.box {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 30rpx;
				background-image: linear-gradient(#FD5674,#FF6448);
				border-radius: 30rpx;
				.item {
					text-align: center;
					width: 48%;
					padding: 30rpx;
					.time {
						font-size: 28rpx;
						color: #fff;
						font-weight: bold;
					}

					.clock {
						display: flex;
						justify-content: center;
						align-items: center;
						margin: 10rpx 0;

						.line {
							width: 100rpx;
							height: 2rpx;
							background-color: #fff;
						}

						image {
							width: 35rpx;
							height: 35rpx;
							margin: 0 20rpx;
						}
					}
				}
			}
		}
	}
</style>